package com.example.commonlib.base.widget;


import com.example.commonlib.ResourceTable;
import ohos.agp.components.Component;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.CommonDialog;
import ohos.app.Context;

public class InputDialog extends CommonDialog {

    private Context mContext;

    private Text mTitle;
    private Text mInput;
    private Text mPassiveText;
    private Text mPositiveText;

    public InputDialog(Context context) {
        this(context, ResourceTable.Layout_base_empty_page);
    }

    public InputDialog(Context context, int theme) {
        super(context);
        mContext = context;
        initView();
    }

    protected InputDialog(Context context, boolean cancelable, RemoveCallback removeCallback) {
        super(context);
        siteRemovable(cancelable);
        registerRemoveCallback(removeCallback);
    }

    public void initView() {
        Component dialogContent = LayoutScatter.getInstance(mContext).parse(ResourceTable.Layout_dialog_input, null, false);

        mTitle = (Text) dialogContent.findComponentById(ResourceTable.Id_title);
        mInput = (Text) dialogContent.findComponentById(ResourceTable.Id_input_content);
        mPassiveText = (Text) dialogContent.findComponentById(ResourceTable.Id_passive_button);
        mPositiveText = (Text) dialogContent.findComponentById(ResourceTable.Id_positive_button);
        setTitleText("");
        setContentCustomComponent(dialogContent);
    }

    public void setPositiveClickListener(final ClickedListener listener) {
        mPositiveText.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (listener != null) {
                    listener.onClick(InputDialog.this, 0);
                }
            }
        });
    };

    public void setPassiveClickListener(final ClickedListener listener) {
        mPassiveText.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                if (listener != null) {
                    listener.onClick(InputDialog.this, 1);
                }
            }
        });
    }

    public String getContent() {
        return mInput.getText().toString();
    }

    public Text getInputView() {
        return mInput;
    }

    public Text getPassiveButton() {
        return mPassiveText;
    }

    public Text getPositiveText() {
        return mPositiveText;
    }

    public void setTitle(String content) {
        mTitle.setText(content);
    }

    public void setHint(String content) {
        mInput.setHint(content);
    }

    public void setContent(String content) {
        mInput.setText(content);
    }

    public String getTitle() {
        return mTitle.getText().toString();
    }

}
